package com.ruoyi.task;

import java.time.LocalDateTime;
import java.time.MonthDay;
import java.time.temporal.TemporalAdjusters;

import javax.annotation.Resource;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.ruoyi.system.service.ISysUserService;

@Component
public class PaeseCurrentWordSize {
	
	ThreadPoolTaskExecutor threadPoolTaskExecutor;
	
	ISysUserService service;
	
	@Resource
	public void setService(ISysUserService service) {
		this.service = service;
	}

	public PaeseCurrentWordSize(ThreadPoolTaskExecutor threadPoolTaskExecutor) {
		this.threadPoolTaskExecutor = threadPoolTaskExecutor;
	}
	
	/**
	 * 当前月字数置为零
	 */
	@Async(value = "threadPoolTaskExecutor")
	@Scheduled(fixedRate = 86400000) // 每天执行一次，这里使用毫秒作为单位  
    public void performMonthlyLastDayTask() {  
        LocalDateTime now = LocalDateTime.now();  
        // 获取当前月份的最后一天  
        MonthDay lastDayOfMonth = MonthDay.from(now.with(TemporalAdjusters.lastDayOfMonth()));  
        // 构建当月的最后一天的LocalDateTime对象  
        LocalDateTime lastDayOfThisMonth = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);  
  
        // 检查当前时间是否接近最后一天的23:59:59  
        if (now.toLocalDate().equals(lastDayOfThisMonth.toLocalDate()) &&  
                now.getHour() == 23 && now.getMinute() == 59 && now.getSecond() >= 50) {  
            // 执行你的任务  
            performTask();  
        }  
    }  
  
    private void performTask() {  
        // 这里写你的任务逻辑  
    	service.clearMonthParseSize();
    }  
	
	
}
